﻿namespace ExpressionsWpf
{
    using System;
    using System.Collections.Generic;
    using System.Linq.Expressions;

    public partial class MainWindow
    {
        public MainWindow()
        {
            InitializeComponent();

            // create some bogus expression
            Expression<Func<int, int, int>> expr = (x, y) =>
                                                   x > 10
                                                       ? y > 20
                                                             ? 100
                                                             : x * (int)Math.Sqrt(x)
                                                       : (int)((x + y) * Math.PI);

            // wrap expression in ExpressionAdapter and then List<ExpressionAdapter>
            // (because a Treeview.ItemSource expects an IEnumerable) and bind TreeView to it
            var source = new List<ExpressionAdapter>
            {
                new ExpressionAdapter(expr, "Expression")
            };
            tvExpression.ItemsSource = source;
        }
    }
}